// pages/mine/address/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fromType:0,//从何处进入  0:个人中心 1：订单页
    addressList:[
      {
        id:0,
        user:"美美美",
        phone:"13524231800",
        province:"湖北省",
        city:"武汉市",
        area:"武昌区",
        street:"友谊大道106号",
        isDefault:true,
      },
      {
        id: 1,
        user: "美美美2",
        phone: "13524231800",
        province: "湖北省",
        city: "武汉市",
        area: "武昌区",
        street: "友谊大道106号",
        isDefault:false,
      },
      {
        id: 2,
        user: "美美美3",
        phone: "13524231800",
        province: "湖北省",
        city: "武汉市",
        area: "武昌区",
        street: "友谊大道106号",
        isDefault: false,
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let fromType = options.from;
    this.setData({
      fromType: fromType
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  deleteAddress(event){
    let id = event.currentTarget.dataset.aid;
    let _this=this;
    console.log(id);
    wx.showModal({
      title: '提示',
      content: '确认删除地址？',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  goBack(event){
    let address = event.currentTarget.dataset.address;
    let fromType = this.data.fromType;
    var thatPages = getCurrentPages()[getCurrentPages().length - 2];//获取当前page实例
    console.log(address);
    if (fromType==1){
      thatPages.setData({
        address: address
      });
      wx.navigateBack({
        
      })
    }
  }
})